package org.box.metadata.shell.parser;

import org.box.metadata.cli.MetaCommandLineParser;
import org.box.metadata.cli.MetaCommandLineParser.ParserType;
import org.box.metadata.cli.annotation.Command;
import org.box.metadata.cli.exception.ParseException;
import org.box.metadata.shell.Shell;
import org.box.metadata.shell.console.ConsoleDefaultConfiguration;

/**
 * Shell's Command Line Interface implementation based on
 * {@link MetaCommandLineParser} and provides Shell's specific validation and
 * parsing methods.
 * 
 * @see MetaCommandLineParser
 * @see Shell
 * 
 * @author <a href="mailto:alexander.box@gmail.com">Alexander Korobka</a>
 * 
 * @param <T>
 *            - a Shell's configuration such as {@link ConsoleDefaultConfiguration}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ShellCLIParser  {

	private final MetaCommandLineParser delegate;

	/**
	 * Constructs a instance of the parser
	 * 
	 * @param cfgClass
	 *            - Shell's configuration class
	 * @param parserType 
	 */
	public ShellCLIParser(ParserType parserType) {
		//FIXME:
		delegate = new MetaCommandLineParser(null, parserType);
	}

	public <T> Command findCommandIn(Class<T> cfgClass, String[] args) {
		try {
			return delegate.findCommandIn(cfgClass, args);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}
	
}
